package com.gusti.turnos.util;

import org.springframework.context.MessageSource;
import org.springframework.context.NoSuchMessageException;

/**
 * 
 * @author gusti
 *
 */
public class MessageUtil {

	private static MessageSource messageSource;

	public void setMessageSource( MessageSource messageSource ) {
		MessageUtil.messageSource = messageSource;
	}

	public static String getMessage( String code ) {

		String message;
		try {
			message = messageSource.getMessage( code, null, null );
		} catch( NoSuchMessageException e ) {
			Debug.error( e );
			message = code;
		}
		return message;
	}

	//Messages constants
	public final static String ERROR_404 = "ERROR_404";
	public final static String ERROR_500 = "ERROR_500";

	public final static String ERROR_AUTHENTICATION_FAILED = "ERROR_AUTHENTICATION_FAILED";
	public final static String ERROR_AUTHORIZATION_FAILED = "ERROR_AUTHORIZATION_FAILED";

	public final static String ERROR_INVALID_PARAMETERS = "ERROR_INVALID_PARAMETERS";
	public final static String ERROR_INVALID_SESSION = "ERROR_INVALID_SESSION";
	public final static String ERROR_INVALID_USER_UUID = "ERROR_INVALID_USER_UUID";

	public final static String ERROR_USER_EMAIL_USED = "ERROR_USER_EMAIL_USED";
	public final static String ERROR_APPOINTMENT_NAME_USED = "ERROR_APPOINTMENT_NAME_USED";

	public final static String EMPTY_RESULT = "EMPTY_RESULT";
	public final static String ERROR_SAVE = "ERROR_SAVE";
}
